package com.example.linkedlist;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import java.util.StringTokenizer;

public class MainActivity extends AppCompatActivity {
    String input="";
    LinkedQueue<Integer> linkedQueue=new LinkedQueue<>();
    EditText editText;
    TextView output;
    EditText editText2,editText3;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void Edit(View view) {
        int editpoint=Integer.parseInt(editText3.getText().toString());
        int editelement=Integer.parseInt(editText2.getText().toString());
        linkedQueue.changeelement(editelement,(editpoint));
        output.setText(linkedQueue.toString());
    }

    public void Delete(View view) {
        linkedQueue.dequeue();
        output.setText(linkedQueue.toString());
    }

    public void reverse(View view) {
        linkedQueue.reverse();
        output.setText(linkedQueue.toString());
    }

    public void Input(View view) {
        editText=(EditText)findViewById(R.id.editText);
        output=(TextView)findViewById(R.id.textView3);
        editText2=(EditText)findViewById(R.id.input2);
        editText3=(EditText)findViewById(R.id.input3);


        //读取输入文本
        input=editText.getText().toString();

        //将输入文本转换为链表
        StringTokenizer stn=new StringTokenizer(input," ,");
        int number;
        while (stn.hasMoreElements()){
            number= Integer.parseInt(stn.nextToken());
            linkedQueue.enqueue(number);
        }

        //放到textView中输出
        output.setText(linkedQueue.toString());

        //清空editText
        editText.setText("");
    }
}
